from typing import List, Optional
from .card import Card

class Player:
    """基础玩家类"""
    def __init__(self, name: str, initial_chips: int = 1000):
        self.name = name
        self.initial_chips = initial_chips  # 保存初始筹码
        self.chips = initial_chips
        self.hole_cards: List[Card] = []
        self.current_bet = 0
        self.is_folded = False
        self.is_all_in = False
    
    def reset(self):
        """重置玩家状态"""
        self.hole_cards = []
        self.current_bet = 0
        self.is_folded = False
        self.is_all_in = False
    
    def receive_cards(self, cards: List[Card]):
        """接收底牌"""
        self.hole_cards = cards
    
    def place_bet(self, amount: int) -> int:
        """下注
        
        Args:
            amount: 下注金额
            
        Returns:
            实际下注金额
        """
        if amount > self.chips:
            amount = self.chips
            self.is_all_in = True
        
        self.chips -= amount
        self.current_bet += amount
        return amount
    
    def win_pot(self, amount: int):
        """赢得奖池
        
        Args:
            amount: 赢得的金额
        """
        self.chips += amount  # 直接增加筹码数

class AIPlayer(Player):
    """AI玩家类"""
    def __init__(self, name: str, initial_chips: int = 1000):
        super().__init__(name, initial_chips)
        self.position = -1  # 在牌桌上的位置
        
    def get_state(self, community_cards: List[Card], total_pot: int, 
                  min_raise: int, players_info: List[dict]) -> dict:
        """获取游戏状态
        
        Args:
            community_cards: 公共牌
            total_pot: 总底池
            min_raise: 最小加注额
            players_info: 其他玩家信息
            
        Returns:
            状态字典
        """
        return {
            'hole_cards': self.hole_cards,
            'community_cards': community_cards,
            'total_pot': total_pot,
            'min_raise': min_raise,
            'chips': self.chips,
            'current_bet': self.current_bet,
            'position': self.position,
            'players_info': players_info
        }
    
    def act(self, state: dict) -> tuple[str, int]:
        """执行动作（由具体的AI实现类重写）
        
        Args:
            state: 当前游戏状态
            
        Returns:
            (动作类型, 下注金额)，动作类型包括：'fold', 'check', 'call', 'raise'
        """
        raise NotImplementedError 